﻿using System;
using System.Data;
using System.Web.UI.WebControls;

using TempEmployees.BLL.Database;

namespace TempEmployees.Web
{
    public partial class GridViewEmployees : BaseGridView
    {
        public delegate void dGotoEmployeeDetailes(string employeeId);
        public delegate void dGotoProduceForms(string employeeId);

        private static readonly int COLUMN_EMPLOYEE_ID = 2;

        public dGotoEmployeeDetailes GotoEmployeeDetailes { get; set; }
        public dGotoProduceForms GotoProduceForms { get; set; }

        public void SetGridView(Filters filters)
        {
            DataTable dataTable = new DataTable();
            GridViewDataTable = dataTable;

            LabelEmptyQueryEmployees.Visible =
                (!DbServices.FillEmployeeGridView(dataTable, filters)) ? true : false;

            base.SetGridView();
        }

        protected void GridViewEmployees_SelectedIndexChanged(object sender, EventArgs e)
        {
            int rowIndex = ViewEmployees.SelectedIndex;
            GridViewRow row = ViewEmployees.Rows[rowIndex];
            string employeeId = row.Cells[COLUMN_EMPLOYEE_ID].Text;
            GotoEmployeeDetailes(employeeId);
        }

        protected void GoToProduceForms_Click(object sender, GridViewEditEventArgs e)
        {
            int rowIndex = e.NewEditIndex;
            GridViewRow row = ViewEmployees.Rows[rowIndex];
            string employeeId = row.Cells[COLUMN_EMPLOYEE_ID].Text;
            GotoProduceForms(employeeId);
        }

        protected override GridView GetGridView()
        {
            return ViewEmployees;
        }

        protected override ObjectDataSource GetDataSource()
        {
            return EmployeesDataSource;
        }
    }
}